import React, {Component} from 'react';
import {Table} from 'antd';
import {connect} from 'react-redux';

import {loadData} from './redux';

import './grade.bundle.less';

class Grade extends Component {

    columns = [
        {
            title: '实验名',
            key: 'name',
            dataIndex: 'name'
        },
        {
            title: '用户',
            key: 'stdnum',
            dataIndex: 'stdnum'
        },
        {
            title: '评阅时间',
            key: 'time',
            dataIndex: 'time'
        },
        {
            title: '评阅教师',
            key: 'teacher',
            dataIndex: 'teacher'
        },
        {
            title: '成绩',
            key: 'grade',
            dataIndex: 'grade'
        }
    ];

    componentDidMount() {
        if (!this.props.loadover) {
            this.props.loadData();
        }
    }

    render() {
        const data = this.props.data || [];
        console.log(data);
        return (
            <div className="grade">
                <div className='title'>实验成绩列表<hr /></div>
                <Table
                    rowKey={record => record.name}
                    columns={this.columns}
                    dataSource={data.data}
                />
            </div>
        );
    }
}

function mapStateToProps(state) {
    console.log(state.grade);
    return state.grade;
}

function mapDispatchToProps(dispatch) {
    return {
        loadData() {
            return dispatch(loadData());
        }
    };
}

export default connect(mapStateToProps, mapDispatchToProps)(Grade);
